from __future__ import with_statement

from concepts import *
from unittest import *

from core.good import *
from core.storage import *


class Food(Good):
    singular =_ ('Food')
    plural   =_ ('Food')


class Fruit(Food):
    singular =_ ('Fruit')
    plural   =_ ('Fruit')


class Apples(Fruit):
    singular =_ ('Apple')
    plural   =_ ('Apples')


class Grapes(Fruit):
    singular =_ ('Grape')
    plural   =_ ('Grapes')


class Olives(Fruit):
    singular =_ ('Olive')
    plural   =_ ('Olives')


class StorageTest(TestCase):
    def test_can_store(self):
        pass
    
    def test_adding_removing(self):
        storage = Storage((Food(800),), unit = 100)
        
        self.assertTrue(storage.is_empty)
        self.assertEquals(storage.capacity,                 800)
        self.assertEquals(storage.capacity_for(Food),       800)
        self.assertEquals(storage.capacity_for(Fruit),      800)
        self.assertEquals(storage.capacity_for(Apples),     800)
        self.assertEquals(storage.free_storage_for(Food),   800)
        self.assertEquals(storage.free_storage_for(Fruit),  800)
        self.assertEquals(storage.free_storage_for(Apples), 800)
        
        left = storage.add_goods(Olives(150))
        
        self.assertFalse(storage.is_empty)
        self.assertEquals(left, None)
        self.assertEquals(storage.capacity,                 800)
        self.assertEquals(storage.capacity_for(Food),       800)
        self.assertEquals(storage.capacity_for(Fruit),      800)
        self.assertEquals(storage.capacity_for(Apples),     800)
        self.assertEquals(storage.capacity_for(Olives),     800)
        self.assertEquals(storage.free_storage_for(Food),   650)
        self.assertEquals(storage.free_storage_for(Fruit),  650)
        self.assertEquals(storage.free_storage_for(Apples), 600)
        self.assertEquals(storage.free_storage_for(Olives), 650)
        
        left = storage.add_goods(Apples(50))
        
        self.assertEquals(left, None)
        self.assertEquals(storage.free_storage_for(Food),   600)
        self.assertEquals(storage.free_storage_for(Fruit),  600)
        self.assertEquals(storage.free_storage_for(Apples), 550)
        self.assertEquals(storage.free_storage_for(Olives), 550)
        
        left = storage.add_goods(Fruit(75))
        
        self.assertEquals(left, Fruit(75))
        self.assertEquals(storage.free_storage_for(Food),   600)
        self.assertEquals(storage.free_storage_for(Fruit),  600)
        self.assertEquals(storage.free_storage_for(Apples), 550)
        self.assertEquals(storage.free_storage_for(Olives), 550)
        
        storage.add_goods(Olives(75))
        storage.remove_goods(Fruit(33))
        storage.remove_goods(Olives(150))
        storage.remove_goods(Food(33))

